package mil.af.amc.adpetracker.dao.hibernate;

import mil.af.amc.adpetracker.dao.MaintenanceEntryDao;
import mil.af.amc.adpetracker.model.MaintenanceEntry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Please fill in this javadoc
 *
 * @author TSgt Jason Ferguson
 */
@Repository("maintenanceEntryDao")
public class HibernateMaintenanceEntryDao extends HibernateGenericDao<MaintenanceEntry> implements MaintenanceEntryDao {

    private static final Log log = LogFactory.getLog(HibernateMaintenanceEntryDao.class);

    public HibernateMaintenanceEntryDao() {
        super(MaintenanceEntry.class);
    }

    public List<MaintenanceEntry> getBySerialNumber(final String serial) {

        Criteria meCriteria = sessionFactory.getCurrentSession().createCriteria(MaintenanceEntry.class);
        meCriteria.add(Restrictions.eq("serial", serial));

        List<MaintenanceEntry> results = null;
        try {
            results = meCriteria.list();
        } catch (HibernateException e) {
            log.debug("getBySerialNumber() threw HibernateException", e);
        }

        return results;

//        return (List<MaintenanceEntry>) getHibernateTemplate().execute(new HibernateCallback() {
//            public Object doInHibernate(Session session) throws HibernateException, SQLException {
//
//                Criteria crit = session.createCriteria(MaintenanceEntry.class);
//                crit.add(Restrictions.eq("serial", serial));
//                return crit.list();
//
//            }
//        }
//
//        );

    }
}
